//
//  XMHeaderReusableView.m
//  XMFilterView
//
//  Created by mac on 2019/11/27.
//  Copyright © 2019 aishangliguo. All rights reserved.
//

#import "XMHeaderReusableView.h"

@interface XMHeaderReusableView ()

@property (nonatomic, strong) UILabel *filterTitle;

@property (nonatomic, strong) UIButton *filterButton;

@end

@implementation XMHeaderReusableView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        [self addSubview:self.filterTitle];
        [self.filterTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.mas_equalTo(self).offset(20);
            make.bottom.mas_equalTo(self).offset(0);
        }];
        [self addSubview:self.filterButton];
        [self.filterButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self).offset(-20);
            make.centerY.mas_equalTo(self.filterTitle);
            make.height.offset(30);
        }];
    }
    return self;
}

//- (void)setHeaderTitle:(NSString *)headerTitle {
//    _headerTitle = headerTitle;
//    self.filterTitle.text = headerTitle;
//}

- (void)setHeaderTitle:(XMTitleModel *)headerTitle {
    self.filterTitle.text = headerTitle.title;
}

- (void)topClick:(UIButton *)sender {
    !_btnClick ? : _btnClick();
}

- (UIButton *)filterButton {
    if (!_filterButton) {
        _filterButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _filterButton.backgroundColor = [UIColor blueColor];
        [_filterButton setTitle:@"上" forState:UIControlStateNormal];
        [_filterButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_filterButton addTarget:self action:@selector(topClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _filterButton;
}

- (UILabel *)filterTitle {
    if (!_filterTitle) {
        _filterTitle = [[UILabel alloc] init];
        _filterTitle.backgroundColor = [UIColor redColor];
        _filterTitle.textAlignment = NSTextAlignmentCenter;
    }
    return _filterTitle;
}



@end
